package com.handu.luna.core.domain.goods;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.handu.luna.core.domain.BaseRepository;

public interface AttributeRepository  extends JpaRepository<Attribute,Long>, BaseRepository<Attribute>,JpaSpecificationExecutor<Attribute>{


	/**
	 * 查询全部商品属性
	 */
	@Query("select b from Attribute b order by attributeSort asc  ")
	Page<Attribute> findAll(Pageable pageable);
	
	/**
	 * 通过name查询
	 * @param name 商品属性name
	 * @return
	 */
	@Query("select g from Attribute g where g.name = :name")
	List<Attribute> findByName(@Param("name") String name);
	/**
	 * 通过name,id查询
	 * @param name 商品属性name
	 * @return
	 */
	@Query("from Attribute u  where u.name = :name AND u.id <> :id")
	public List<Attribute> findByNameAndId(@Param("name") String name,@Param("id") Long id);
	
	@Query("from Attribute b where b.inputValues like CONCAT('%',:inputValues,'%')")
	Attribute findByInputValues(@Param("inputValues") String inputValues);
	
	@Query("from Attribute b where b.name like CONCAT('%',:name,'%')")
	Attribute findByNameValue(@Param("name") String name);
	
}
